package com.dulichdanang;

import java.util.ArrayList;
import java.util.List;

import com.dulichdanang.galery.GalleryView;
import com.dulichdanang.location.locationCat.LoadCatActivity;
import com.dulichdanang.location.locationCat.LocationCatActivity;
import com.dulichdanang.location.locations.LocationsActivity;
import com.dulichdanang.rssreader.SplashActivity;
import com.dulichdanang.searchLocation.SearchLocationActivity;
import com.dulichdanang.weather.Weather;

import android.os.Bundle;
import android.os.Looper;
import android.app.Activity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ListView;

public class HomeActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home);
		// ListView lv = (ListView)findViewById(R.id.lvHome);
		GridView gv = (GridView) findViewById(R.id.gvHome);
		// Tạo danh sách các chức năng
		final List<HomeListItem> items = new ArrayList<HomeListItem>();
		items.add(new HomeListItem() {
			{
				imageResource = R.drawable.travel;
				title = R.string.name_travel;
				subTitle = R.string.des_travel;

			}
		});
		items.add(new HomeListItem() {
			{
				imageResource = R.drawable.search;
				title = R.string.name_search;
				subTitle = R.string.des_search;

			}
		});
		items.add(new HomeListItem() {
			{
				imageResource = R.drawable.map;
				title = R.string.name_map;
				subTitle = R.string.des_map;

			}
		});
		items.add(new HomeListItem() {
			{
				imageResource = R.drawable.news;
				title = R.string.name_news;
				subTitle = R.string.des_news;

			}
		});
		items.add(new HomeListItem() {
			{
				imageResource = R.drawable.weather;
				title = R.string.name_weather;
				subTitle = R.string.des_weather;

			}
		});
		items.add(new HomeListItem() {
			{
				imageResource = R.drawable.galery;
				title = R.string.name_galery;
				subTitle = R.string.galery;

			}
		});
		items.add(new HomeListItem() {
			{
				imageResource = R.drawable.about;
				title = R.string.name_about;
				subTitle = R.string.des_about;

			}
		});

		HomeAdapter adapter = new HomeAdapter(this, items);
		gv.setAdapter(adapter);
		OnItemClickListener click = new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				Intent intent;
				switch (position) {
				case 0:
					intent = new Intent(HomeActivity.this,
							LoadCatActivity.class);
					intent.putExtra("data", items.get(position).title);
					startActivity(intent);
					break;
				case 1:
					intent = new Intent(HomeActivity.this,SearchLocationActivity.class);
					startActivity(intent);
					break;
				case 3:
					intent = new Intent(HomeActivity.this, SplashActivity.class);
					// intent.putExtra("data",items.get(position).title);
					startActivity(intent);
					break;
				case 4:
					intent = new Intent(HomeActivity.this, Weather.class);
					// intent.putExtra("data",items.get(position).title);
					startActivity(intent);
					break;
				case 5:
					intent = new Intent(HomeActivity.this, GalleryView.class);
					// intent.putExtra("data",items.get(position).title);
					startActivity(intent);
					break;
				case 6:
					intent = new Intent(HomeActivity.this, Map.class);
					// intent.putExtra("data",items.get(position).title);
					startActivity(intent);
				default:
					break;
				}
			}
		};
		gv.setOnItemClickListener(click);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_home, menu);
		return true;
	}

	@Override
	public void onAttachedToWindow() {
		super.onAttachedToWindow();
		Window window = getWindow();
		window.setFormat(PixelFormat.RGBA_8888);
	}

}
